package com.ruoyi.web.controller.init;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysDictType;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.PostConstruct;
import java.util.List;

@Configuration
public class LoadData {


    private static final Logger log = LoggerFactory.getLogger(LoadData.class);
    @Autowired
    public ISysDictTypeService sysDictTypeService;
    @Autowired
    public ISysDictDataService  dictDataService;
    @Autowired
        public ISysDeptService deptService;
    @PostConstruct
     public  void init() {
        List<SysDictType> sysDictTypes = sysDictTypeService.selectDictTypeAll();
        for (SysDictType sysDictType : sysDictTypes) {
            SysDictData data = new SysDictData();
            data.setDictType(sysDictType.getDictType());
            List<SysDictData> sysDictData = dictDataService.selectDictDataList(data);
            DictUtils.setDictCache(sysDictType.getDictType(),sysDictData);
        }
        SysDept dept = new SysDept();
        List<SysDept> sysDepts = deptService.selectDeptListAll();
        for (SysDept sysDept : sysDepts) {
            DictUtils.setDictCacheName("dept"+sysDept.getDeptId(),sysDept.getDeptName());
        }
    }
}
